package com.gxgeek.order.message;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author gaoxing
 * @create 2018-03-28 下午3:26
 */
@Slf4j
@Component
public class MqReceiver {

//    @RabbitListener(queues = "myQueue")//只监听队列
//    @RabbitListener(queuesToDeclare= @Queue("myQueue"))//监听并创建队列
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange("myExchange"),
            value = @Queue("myQueue"))
    )//exchange 和 队列绑定
    public void proess(String message){

        log.info("MqReceiver:{}",message);
    }

    /**
     * 数码供应
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange("myOrder"),
            key = "digital",//路由Key
            value = @Queue("digitalOrder"))
    )//exchange 和 队列绑定
    public void proessdigital(String message){

        log.info("digital MqReceiver:{}",message);
    }

    /**
     * 水果
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange("myOrder"),
            key = "fruit",//路由Key
            value = @Queue("fruitOrder"))
    )//exchange 和 队列绑定
    public void proessFruit(String message){

        log.info("fruit MqReceiver:{}",message);
    }
}
